<template>
  <div>
    <div class="home-header">
        <h3>饭了么</h3>
      </div>
      <h2><input type="text" v-model="canteenWindowName"></h2>
      <button class="change" @click="change">保存名字</button>
      <button class="add" @click="addDish">增加菜品</button>
      <button class="quit" @click="quit">退出登录</button>
      <img src="@/assets/tubiao.png">

      <van-tabbar route v-model="active">
        <van-tabbar-item to="/mydish" icon="home-o">首页</van-tabbar-item>
        <van-tabbar-item to="/mine" icon="user-o">我的</van-tabbar-item>
      </van-tabbar>
  </div>
</template>

<script>
import {changeName} from '@/api/shangjia/mine'
import { mapState,mapActions} from "vuex";
export default {
name:"user",
data() {
    return {
        active:0,
        canteenWindowName:''
    }
},
computed: {
      ...mapState('user', ['userInfo'])
    },
    created() {
        this.canteenWindowName=this.userInfo.canteenWindowName
    },
methods:{
    ...mapActions('user', ['logout','updateUserInfo']),
    change(){
        const updatedUserInfo = {
        ...this.userInfo,
        canteenWindowName: this.canteenWindowName,
      };
      this.updateUserInfo(updatedUserInfo);

      // 调用接口更新用户信息
      this.updateUser();
    },
    updateUser(){
        changeName(this.userInfo.canteenWindowId,this.userInfo.canteenWindowName).then((res)=>{
            console.log('保存返回信息',res);
        })
    },

    addDish(){
        this.$router.push('/addDish')
    },
     //退出登录,清楚local值，跳到登录页
     quit(){
        this.logout();
        this.$toast('退出成功');
        this.$router.push('/login')
    }
}
}
</script>

<style lang="less" scoped>
.home-header{
    width: 100%;
    height: 36px;
    background-color: rgb(10, 135, 245);
    position: fixed;
    top: 0;
    z-index: 1;
    h3{
        text-align: center;
        color: aliceblue;
        margin-top: 5px;
    }
   
}
h2{
    margin-top: 40px;
    text-align: center;
    width: 170px;
    input{
        border: none;
        margin-left: 13.33333vw;
        text-align: center;
    }
}
img{
    width: 110px;
    height: 110px;
    z-index: -1;
    border-radius: 50px;
    margin-top: 170px;
    margin-left: 140px;
}
.bt{
    display: block;
    border: none;
    width: 90px;
    height: 30px;
    border-radius: 20px;
    color: aliceblue;
}
.change{
    background-color: rgb(72, 185, 250);
    margin-left: 145px;
    margin-top: 25.33333vw;
   .bt();
}
.add{
    .bt();
    margin-left: 145px;
    margin-top: 40px;
    background-color: rgb(53, 175, 245);
}
.quit{
    .bt();
    margin-left: 145px;
    margin-top: 40px;
    background-color: red;
}


</style>